<?xml version="1.0" encoding="utf-8"?>
<!--
        dl2rdf.xsl
        Created by Ford Parsons on 2007-02-08.
        Copyright (c) 2007 Ford Parsons. All rights reserved.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:NC="http://home.netscape.com/NC-rdf#"
xmlns:bib="http://purl.org/net/biblio#"
xmlns:prism="http://prismstandard.org/namespaces/1.2/basic/"
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:exsl="http://exslt.org/common"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="str" version="1.0">
  <xsl:import href="str/str.xsl" />
  <xsl:output encoding="UTF-8" indent="yes" method="xml" />
  <xsl:template match="/">
    <RDF:RDF>
      <xsl:apply-templates select="library/items/book" />
    </RDF:RDF>
  </xsl:template>
  <xsl:template match="library/items/book">
    <RDF:Description RDF:about="urn:isbn:{@asin}"
    dc:title="{@title}" dc:type="book" dc:publisher="{@publisher}"
    dc:identifier="ISBN {@asin}"
    prism:edition="{@edition}" bib:pages="{@pages}">
      <xsl:attribute name="dc:date">
        <xsl:call-template name="format_date">
          <xsl:with-param name="string" select="@published" />
        </xsl:call-template>
      </xsl:attribute>
      <xsl:for-each select="str:split(@author, '&#xA;')">
        <dc:creator>
          <xsl:call-template name="format_author">
            <xsl:with-param name="string" select="." />
          </xsl:call-template>
        </dc:creator>
      </xsl:for-each>
    </RDF:Description>
  </xsl:template>
  <!--Reformat author names (split after middle initial if it's there)-->
  <xsl:template name="format_author">
    <xsl:param name="string" />
    <xsl:if test="$string">
      <xsl:choose>
        <xsl:when test="contains($string,'. ')">
          <xsl:value-of select="substring-after($string,'. ')" />
          <xsl:value-of select="', '" />
          <xsl:value-of select="substring-before($string,'. ')" />
          <xsl:value-of select="'.'" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="substring-after($string,' ')" />
          <xsl:value-of select="', '" />
          <xsl:value-of select="substring-before($string,' ')" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>
  <!--Reformat dates (for some reason DL saves dates like dd-mm-yyyy)-->
  <xsl:template name="format_date">
    <xsl:param name="string" />
    <xsl:if test="string-length($string) = 10">
      <xsl:value-of select="substring($string,7,4)" />
      <xsl:value-of select="'-'" />
      <xsl:value-of select="substring($string,1,2)" />
      <xsl:value-of select="'-'" />
      <xsl:value-of select="substring($string,4,2)" />
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>
